package org.gxlu.com.storm.wc;

import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.StormSubmitter;
import org.apache.storm.topology.TopologyBuilder;
import org.apache.storm.tuple.Fields;

public class WordCountTopology {

	public static void main(String[] args) throws Exception {
 
		TopologyBuilder builder = new TopologyBuilder();
		builder.setSpout("wcSpout", new WcSpout(),1) ; //并行度 1
		builder.setBolt("splitBolt", new SplitBolt(),2).shuffleGrouping("wcSpout") ; 
		builder.setBolt("countBolt", new CountBolt(),2).fieldsGrouping("splitBolt", new Fields("word"));
		
		Config config = new Config();
		//config.setNumAckers(1);
		config.setNumWorkers(2);  // 2个 worker jvm进程
		config.setDebug(true);
		
		if(args!=null && args.length>0){
			StormSubmitter.submitTopology(args[0], config, builder.createTopology());
			
		}else{
			LocalCluster cluster = new LocalCluster();
			cluster.submitTopology("localWordCount", config, builder.createTopology());
		}
	
	}

}
